package com.rem.springboot2.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Rem
 * @date 2021-03-19
 */

@Controller
public class My4RequestController {


    @GetMapping("/goto")
    public String gotoPage(HttpServletRequest request) {
        request.setAttribute("success", "yse");
        request.setAttribute("code", 200);
        return "forward:/success";
    }


    @ResponseBody
    @GetMapping("/success")
    public Map<String, Object> success(@RequestAttribute("success") String success,
                                       HttpServletRequest request) {
        Object code = request.getAttribute("code");
        Map<String, Object> map = new HashMap<>(2);
        map.put("code", code);
        map.put("success", success);
        return map;
    }

}
